package com.nbjtjc.safe.api.emg.handle;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nbjtjc.safe.bean.Page;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.emg.handle.EmgEventMapper;
import com.nbjtjc.safe.model.emg.handle.EmgEvent;
import com.nbjtjc.safe.model.emg.handle.EmgHandle;
import com.nbjtjc.safe.service.emg.handle.EmgEventService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.management.ValueExp;
import java.util.List;

@RestController
@RequestMapping("/emgEvent")
@CrossOrigin("*")
@Api("应急事件")
public class EmgEventController {
    @Autowired
    private EmgEventService emgEventService;

    @Autowired
    private EmgEventMapper emgEventMapper;

    @RequestMapping(value = "/add",method = {RequestMethod.POST})
    @ApiOperation("添加事件")
    public Result add(@RequestBody EmgEvent emgEvent){
        Result result=new Result();
        try {
            result=emgEventService.add(emgEvent);
        } catch (Exception e) {
            e.printStackTrace();
            result.setFalse(e.getMessage());
        }
        return result;
    }
    @RequestMapping(value = "/countEventLevel",method = {RequestMethod.POST})
    @ApiOperation("添加事件")
    public Result countEventLevel(@RequestBody EmgEvent emgEvent){
        Result result=new Result();
        try {
            result=emgEventService.countEventLevel(emgEvent);
        } catch (Exception e) {
            e.printStackTrace();
            result.setFalse(e.getMessage());
        }
        return result;
    }
    @RequestMapping(value = "/update",method = {RequestMethod.POST})
    public Result update(@RequestBody EmgEvent emgEvent){
        Result result=new Result();
        try {
            result=emgEventService.update(emgEvent);
        } catch (Exception e) {
            e.printStackTrace();
            result.setFalse(e.getMessage());
        }
        return result;
    }
    @RequestMapping(value = "/delete",method = {RequestMethod.POST})
    public Result delete(@RequestBody EmgEvent emgEvent) {
        Result result=new Result();
        try {
            result=emgEventService.delete(emgEvent);
        } catch (Exception e) {
            e.printStackTrace();
            result.setFalse(e.getMessage());
        }
        return result;
    }

    @RequestMapping(value = "/find",method = {RequestMethod.POST})
    public Result find(@RequestBody EmgEvent emgEvent){
        Result result=new Result();
        try {
            PageHelper.startPage(emgEvent.getPageCurrent(),emgEvent.getPageSize());
            List<EmgEvent> emgEvents= emgEventMapper.search(emgEvent);
            result.setData(new PageInfo<>(emgEvents));
        } catch (Exception e) {
            e.printStackTrace();
            result.setFalse(e.getMessage());
        }
        return result;
    }
}
